import java.util.ArrayList;

public class CircularShift {


	ArrayList<String> list;
	ArrayList<String> newList = new ArrayList<String>();
	
	
    public CircularShift(LineStorage line) {
    	list = line.getSentences();
    	shift();
    }
    
    /*shift takes the list of sentences and shifts each word
     *to the back of the line to create a new sentence. These
     *sentences are then added to newList
     */ 
    public void shift(){
    	int listSize = list.size();
    	int shiftIndex = 0;
    	int shiftCounter = 0;
    	

	    for(int listIndex = 0; listIndex < listSize; listIndex++){
		    String temp = list.get(listIndex);
	    	String[] stringArray = temp.split(" ");
	    	int sentenceSize = stringArray.length;
		    while (shiftCounter < sentenceSize){
		 		temp = stringArray[(shiftIndex + shiftCounter)];
		    	
		    	//recreate sentence 
		    	while (shiftIndex < (sentenceSize - 1)){
		    		shiftIndex++;
		    		temp = temp + " " + stringArray[((shiftIndex + shiftCounter) % sentenceSize)];
		    	}
		    	
		    	//Add shifted sentence to newList, increment shift counter, reset shift index
		    	newList.add(temp);
		    	shiftCounter++;
		    	shiftIndex = 0;
		    }
		    //Reset shift count, shift index
		    shiftCounter = 0;
		    shiftIndex = 0;
	    }
    }
    
    
    public ArrayList<String> getList(){
    	return newList;
    }
    
}